// renderengine.hpp
//

#ifndef _RENDERENGINE_HPP
#define _RENDERENGINE_HPP

#include "base.hpp"
#include "pipeline.hpp"
#include "sdlayout.hpp"



// GroupPipelineBinding
//
struct GroupPipelineBinding
{
  EntityGroup group;
  PipelineID pipeline;
};



// RenderModeInfo
//
struct RenderModeInfo
{
  RenderModeInfo ( std::vector<GroupPipelineBinding> group_pipeline_bindings )
    : group_pipeline_bindings(group_pipeline_bindings)
  {
  }
  
  std::vector<GroupPipelineBinding> group_pipeline_bindings;
};



// RenderMode
//
struct RenderMode
{
  RenderMode ( RenderModeInfo info )
  {
    for (auto binding: info.group_pipeline_bindings)
      {
        if (group_pipeline.size() <= binding.group)
          group_pipeline.resize(binding.group + 1, -1);
        group_pipeline[binding.group] = binding.pipeline;
      }
  }
  
  // pipeline by group id
  std::vector<PipelineID> group_pipeline; 
};



// RenderEngine
//
class RenderEngine
{
public:
  SDLayout &get_sd_layout () { return sd_layout; }
  
  PipelineID register_pipeline ( PipelineInfo info );
  RenderModeID register_render_mode ( RenderModeInfo info );

  Pipeline *get_group_pipeline ( RenderModeID render_mode,
                                 EntityGroupID group );
  size_t get_render_mode_count () { return registered_render_modes.size(); }
  
private:
  SDLayout sd_layout{};

  std::vector<Pipeline> registered_pipelines;
  std::vector<RenderMode> registered_render_modes;
};



#endif
